#! /usr/bin/env bash

interface=$1
channel=$2
bssid=$3
essid=$4

if [[ ( -z "$interface" ) || ( -z "$channel" ) || ( -z "$bssid" ) ]]
then
	echo Usage: $(basename $0) interface channel bssid [essid]
	exit
fi

echo $$ >> "$(echo $0 | sed s/\.sh$//).pid"

cd "$(dirname "$0")"
cd ..

identifier=$(echo $bssid | tr '[A-Z]' '[a-z]' | tr --delete ':')
if [ -n "$essid" ]
then
	identifier=$identifier-$(echo $essid | tr '[A-Z]' '[a-z]' | tr --complement --delete '[a-z0-9]')
fi

cd capture
mkdir -p $identifier
cd $identifier

airodump-ng --bssid $bssid --channel $channel --write $(date +"%Y-%m-%d-%H-%M-%S") $interface

